package com.pay.config;

import com.lly835.bestpay.config.WxPayConfig;
import com.lly835.bestpay.service.BestPayService;
import com.lly835.bestpay.service.impl.BestPayServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class BestPayConfig {
    @Value("${wxPayConfig.appId}")
    String appId;

    @Value("${wxPayConfig.mchId}")
    String mchId;

    @Value("${wxPayConfig.mchKey}")
    String mchKey;

    @Value("${wxPayConfig.notifyUrlPrefix}")
    String notifyUrlPrefix;

    @Value("${wxPayConfig.returnUrl}")
    String returnUrl;

    @Bean
    public BestPayService bestPayService(){
        WxPayConfig wxPayConfig = new WxPayConfig();
        wxPayConfig.setAppId(appId);
        wxPayConfig.setMchId(mchId);
        wxPayConfig.setMchKey(mchKey);
        wxPayConfig.setNotifyUrl(notifyUrlPrefix+"/pay/notify");
        wxPayConfig.setReturnUrl(returnUrl);

        BestPayServiceImpl bestPayService = new BestPayServiceImpl();
        bestPayService.setWxPayConfig(wxPayConfig);
        return bestPayService;
    }
}
